<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>新生学员管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/X-admin/css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-nav">
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:29px">ဂ</i> <i class="layui-icon" style="line-height:30px">刷新</i></a>
        </div>
      	<xblock style="height:40px" >
        <button class="layui-btn" onclick="addAll()"><i class="layui-icon">&#xe654;</i>批量启用</button>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量禁用</button>
        <form style="float:right;" class="layui-form" action="__MODULE__/Students/newStu" method="get">
		      <div class="layui-input-inline">
		        <div class="layui-input-inline">
		        	<input type="text" name="name"  lay-verify="required" placeholder="按姓名查找" autocomplete="off" class="layui-input">
		        </div>
	        </div>
	        <!-- <div class="layui-input-inline">
		        <div class="layui-input-inline">
		        	<input type="text" name="title" required="" lay-verify="required" placeholder="按班级查找" autocomplete="off" class="layui-input">
		        </div>
	        </div> -->
	        <div class="layui-input-inline" style="width:180px">
		        <select name="class" width="50px" >
					   <option value="">按班级查找</option>
              <foreach name="classs" item="rows" >
					     <option value="{$rows['id']}" >{$rows['name']}</option>
              </foreach>
			  	  </select>
		  	</div>
		  	<button class="layui-btn" type="submit" lay-filter="formDemo"><i class="layui-icon" style="font-size: 20px;" >&#xe615;</i>搜索</button>
        	</form>
        </xblock>

        <div class="layui-tab">
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
        
					<table class="layui-table">
					  <colgroup>
					    <col width="5%">
					    <col width="15%">
					    <col width="15%">
					    <col width="15%">
              <col width="15%">
					    <col width="15%">
					    <col>
					  </colgroup>
					  <thead>
					    <tr>
                <th>
                  <input type="checkbox" id="all" onchange="dianji()" value="" title="全选" lay-skin="primary">
                </th>
					      <th>姓名</th>
					      <th>班级</th>
					      <th>小组</th>
					      <th>角色</th>
					      <th>状态</th>
					      <th>操作</th>
					    </tr> 
					  </thead>
					  <tbody>
            <!-- <form action="" class="layui-form" method="post"> -->
					  	<foreach name="list" item="row" >
					  		
							    <tr>
                    <td>
                      <input type="checkbox" name="ck" value="{$row['id']}">
                    </td>
							      <td>{$row['name']}</td>
							      <td>{$row['class']}</td>
							      <td>{$row['team']}</td>
							      <td>{$row['role_id']}</td>
							      <td>{$row['can_login']}</td>
							      <td class="td-manage">
                      <a title="个人信息" href="javascript:;" onclick="admin_edit('编辑','__MODULE__/Students/show/id/{$row['id']}','4','','510')" class="ml-5" style="text-decoration:none"><i style="font-size: 30px; color: #1E9FFF;" class="layui-icon">&#xe63c;</i></a>&nbsp;&nbsp;&nbsp;&nbsp;

	                    <a title="点击启用" href="javascript:;" onclick="admin_str(this,'{$row['id']}')" style="text-decoration:none"><i class="layui-icon" style="font-size: 30px; color: #009688;" >&#xe616;</i></a>&nbsp;&nbsp;&nbsp;
                      <a title="点击禁用" href="javascript:;" onclick="admin_del(this,'{$row['id']}')" style="text-decoration:none"><i class="layui-icon" style="font-size: 35px; color: #FF5722;" >&#x1007;</i></a>
	                  </td>
							    </tr>
              </foreach>
            </tbody>
          </table>
					<div class="total">共{$total}条数据</div>
          <!-- 分页信息 -->
          <div id="pages"></div>
				</div>
			</div>
		</div>
	
        <script src="__PUBLIC__/X-admin/lib/layui/layui.js" charset="utf-8"></script>
        <script src="__PUBLIC__/X-admin/js/x-layui.js" charset="utf-8"></script>
        
        <script>
          //全选   全不选
            function dianji() {
              var flag = document.getElementById("all").checked;
                  // alert(flag)
                  var cks = document.getElementsByName("ck");
                    if (flag) {
                    for ( var i = 0; i < cks.length; i++) {
                    cks[i].checked = true;
                    }
                  } else {
                  for ( var i = 0; i < cks.length; i++) {
                  cks[i].checked = false;
                  }
              }
            }
        </script>

        <script>

             layui.use(['laydate','element','laypage','layer','form'], function(){
                $ = layui.jquery;//jquery
    				    // var form = layui.form();
                laydate = layui.laydate;//日期插件
                lement = layui.element();//面包导航
                laypage = layui.laypage;//分页
                layer = layui.layer;//弹出层
                form = layui.form();
              

              //以上模块根据需要引入
              //调用分页
              laypage({
                cont: 'pages',
                curr: {$curr},
                groups: 5,
                pages: {$page}, //得到总页数
                skip: true,
                jump: function(obj, first){
                  var url = window.location.href;
                  if (url.indexOf('?') < 0) {
                      url = window.location.href;
                  }else{
                      url=url.substr(0, url.indexOf('?'));
                  }
                  search="{$search}";
                  if (!first) {
                    window.location.href=url+search+"/p/"+obj.curr+".html";
                  }

                }
              }); 
              
            });

            //监听提交
              form.on('submit(save)', function(data){
                console.log(data);
                //发异步，把数据提交给php
                layer.alert("保存成功", {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
                return false;
              });

              //批量启用
              function addAll () {

                a = [];
                $("input[name='ck']").each(function(){
                  // alert($(this));
                  // alert($(this).is(":checked"));
                  if($(this).is(":checked")){
                    //获取被选中的复选框的id
                    id=$(this).val();
                    //把所有选中的id  存储在数组a
                    a.push(id);
                  }
                });

                if(a.length!=0){
                  layer.confirm('确认要启用吗？',function(index){
                      //捉到所有被选中的，发异步进行启用

                      $.get("__MODULE__/Students/action",{ids:a},function(data){
                        if(data=="失败"){
                          alert("失败");
                        }
                        // alert(data);
                      });
                      layer.msg('启用成功', {icon: 1});
                      reload();
                  });

                }else{
                    layer.msg('你没选中任何选项', {icon: 2});
                }
             }


            //批量禁用
             function delAll () {

                a = [];
                $("input[name='ck']").each(function(){
                  // alert($(this));
                  // alert($(this).is(":checked"));
                  if($(this).is(":checked")){
                    //获取被选中的复选框的id
                    id=$(this).val();
                    //把所有选中的id  存储在数组a
                    a.push(id);
                  }
                });

                if(a.length!=0){
                  layer.confirm('确认要禁用吗？',function(index){
                      //捉到所有被选中的，发异步进行禁用

                      $.get("__MODULE__/Students/stops",{ids:a},function(data){
                        if(data=="失败"){
                          alert("失败");
                        }
                        // alert(data);
                      });
                      layer.msg('禁用成功', {icon: 1});
                      reload();
                  });

                }else{
                  layer.msg('你没选中任何选项', {icon: 2});
                }
             }
             /*添加*/
            function admin_add(title,url,w,h){
                x_admin_show(title,url,w,h);
            }
            //编辑
            function admin_edit (title,url,id,w,h) {
                x_admin_show(title,url,w,h); 
            }
            /*删除*/
            function admin_str(obj,id){
                layer.confirm('确认通过启用吗？',function(index){
                    //发异步审核数据
                    $.post("__MODULE__/Students/start",{id:id},function(data){
                      if(data=="失败"){
                          alert('启用失败');
                      }
                    });
                    $(obj).parents("tr").remove();
                    layer.msg('已启用!',{icon:1,time:1000});
                    // reload();
                });
            }
            function admin_del(obj,id){
                layer.confirm('确认要禁用吗？',function(index){
                    //发异步审核数据
                    $.post("__MODULE__/Students/stop",{id:id},function(data){
                      if(data=="失败"){
                          alert('禁用失败');
                      }
                    });
                    $(obj).parents("tr").remove();
                    layer.msg('已禁用!',{icon:1,time:1000});
                    // reload();
                });
            }
            </script>
            <script>
                function reload(){
                  location.replace(location.href);
                }
            </script>
    </body>
</html>